@echo off
chcp 65001 > nul
setlocal enabledelayedexpansion

echo ==============================================
echo Start creating Redis Cluster node dir and config...
echo ==============================================

set "ports=7000 7001 7002 7003 7004 7005"
set "root_dir=D:\Program Files\Redis-x64-5.0.10\"
set "template_file=redis-template.conf"

if not exist "!template_file!" (
    echo Error: Template file not found: !template_file!
    pause
    exit /b 1
)

for %%p in (%ports%) do (
    set "node_dir=!root_dir!%%p"
    echo Processing node: %%p, Path: !node_dir!

    if not exist "!node_dir!" (
        mkdir "!node_dir!"
        echo Created dir: !node_dir!
    )

    > "!node_dir!\redis.windows.conf" (
        for /f "usebackq delims=" %%l in ("!template_file!") do (
            set "line=%%l"
            set "line=!line:{PORT}=%%p!"
            echo !line!
        )
    )

    echo Generated config: !node_dir!\redis.windows.conf
    echo ----------------------------------------------
)

echo ==============================================
echo All dir and config files created successfully!
echo Node dirs: !root_dir!7000 ~ !root_dir!7005
echo ==============================================
endlocal
pause
